package com.ykdl.member.kid.circle;

import java.util.ArrayList;

import net.wxxr.dataparse.model.DataParseError;
import net.wxxr.dataparse.model.DataState;
import net.wxxr.http.interfaces.ITag;
import net.wxxr.http.request.HttpBaseRequest;
import oauth.signpost.http.HttpParameters;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.ykdl.member.kid.R;
import com.ykdl.member.constant.KidConfig;
import com.ykdl.member.kid.beans.ImageBean;
import com.ykdl.member.kid.beans.InformsBean;
import com.ykdl.member.kid.beans.ResetPasswordBean;
import com.ykdl.member.kid.gears.BaseScreen;
import com.ykdl.net.manager.TaskManager;
import com.ykdl.net.manager.Wxxr;
/**
 * 
 *问题或者回复的举报页面
 *
 * 
 * @see
 * @since 1.0
 */
public class ReportActivity extends BaseScreen implements OnClickListener{
	private Button report_rsgj,report_eysr,report_mgxx,report_sq,report_eygg,report_qt,report_delete;
	private RelativeLayout layout;
	private String  group_id ,item_id,item_type,item_category;
	private ArrayList<String> report_list = new ArrayList<String>();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ias2_report);
		group_id = getIntent().getStringExtra(TopicAndResultActivity.STR_GROUP_ID);
		item_id = getIntent().getStringExtra(TopicAndResultActivity.STR_REPORT_ID);
		item_type = getIntent().getStringExtra(TopicAndResultActivity.STR_REPORT_TYPE);
		findViewById(R.id.report_sure).setOnClickListener(this);
		report_rsgj = (Button) findViewById(R.id.report_rsgj);
		report_rsgj.setOnClickListener(this);
		report_eysr = (Button) findViewById(R.id.report_eysr);
		report_eysr.setOnClickListener(this);
		report_mgxx = (Button) findViewById(R.id.report_mgxx);
		report_mgxx.setOnClickListener(this);
		report_sq = (Button) findViewById(R.id.report_sq);
		report_sq.setOnClickListener(this);
	    report_eygg = (Button) findViewById(R.id.report_eygg);
		report_eygg.setOnClickListener(this);
		report_qt = (Button) findViewById(R.id.report_qt);
		report_qt.setOnClickListener(this);
		
		report_delete = (Button)findViewById(R.id.report_delete);
		report_delete.setOnClickListener(this);
		
		findViewById(R.id.iask_close).setOnClickListener(this);
		
		
		layout = (RelativeLayout)findViewById(R.id.layout);
		
	}
	
	
	




	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.report_sure:
			if (report_list.size()>0) {
				reportTopic();
			}else {
				Toast.makeText(mContext, "请选择举报内容", Toast.LENGTH_SHORT);
			}
			break;
		case R.id.report_rsgj:
			if (report_rsgj.isSelected()) {
				report_rsgj.setSelected(false);
				report_list.remove(report_rsgj.getText().toString());
			}else {
				report_rsgj.setSelected(true);
				report_list.add(report_rsgj.getText().toString());
			}
			break;
		case R.id.report_eysr:
			if (report_eysr.isSelected()) {
				report_eysr.setSelected(false);
				report_list.remove(report_rsgj.getText().toString());
			}else {
				report_eysr.setSelected(true);
				report_list.add(report_rsgj.getText().toString());
			}
			break;
		case R.id.report_mgxx:
			if (report_mgxx.isSelected()) {
				report_mgxx.setSelected(false);
				report_list.remove(report_rsgj.getText().toString());
			}else {
				report_mgxx.setSelected(true);
				report_list.add(report_rsgj.getText().toString());
			}
			break;
		case R.id.report_eygg:
			if (report_eygg.isSelected()) {
				report_eygg.setSelected(false);
				report_list.remove(report_rsgj.getText().toString());
			}else {
				report_eygg.setSelected(true);
				report_list.add(report_rsgj.getText().toString());
			}
			break;
		case R.id.report_sq:
			if (report_sq.isSelected()) {
				report_sq.setSelected(false);
				report_list.remove(report_rsgj.getText().toString());
			}else {
				report_sq.setSelected(true);
				report_list.add(report_rsgj.getText().toString());
			}
			break;
		case R.id.report_qt:
			if (report_qt.isSelected()) {
				report_qt.setSelected(false);
				report_list.remove(report_rsgj.getText().toString());
			}else {
				report_qt.setSelected(true);
				report_list.add(report_rsgj.getText().toString());
			}
			break;
		case R.id.iask_close:
			finish();
			break;
		}
	}
	// 举报
	private void reportTopic() {
		StringBuffer sb = new StringBuffer();
		if (report_list.size()>1) {
			sb.append(report_list.get(0));
			for (int i = 1; i < report_list.size(); i++) {
				sb.append(",").append(report_list.get(i));
			}
		}else if (report_list.size()==1) {
			sb.append(report_list.get(0));
		}
		showProgress("正在发送请稍等...");
		String  pageurl = KidConfig.GET_ALL_GROUPS+"/"+group_id+"/informs";
		HttpParameters bodyParams = new HttpParameters();
		bodyParams.put("item_id", item_id);
		bodyParams.put("item_type", item_type);
		bodyParams.put("item_category", sb.toString());
		HttpBaseRequest request  =  Wxxr.getInstance().postBaseRequest(pageurl, bodyParams,null);
		 TaskManager.startHttpRequest(request, new reportTopicTag(),  ResetPasswordBean.class);
		 
	}
	class reportTopicTag implements ITag {

		@Override
		public void refreshUI(Object t, DataState ds) {
			// TODO Auto-generated method stub
			
			finishProgress();
			if (t instanceof ResetPasswordBean) {
				ResetPasswordBean bean = (ResetPasswordBean)t;
				if (bean.getStatus()==0) {
					Toast.makeText(mContext, "举报成功", 1).show();
					ReportActivity.this.finish();
				}
				
			}
			
		}

		@Override
		public boolean refreshError(DataParseError parseError) {
			// TODO Auto-generated method stub
			finishProgress();
			Toast.makeText(mContext, "举报失败", 1).show();
			return false;
		}

		@Override
		public void refreshCancel() {
			// TODO Auto-generated method stub
			
		}
		
	}
}
